MBasic: Miscellaneous Commands
Miscellaneous Commands Intro This chapter includes the "normal" BASIC commands that are included with most versions of BASIC, as well as commands specific to Atom BASIC. Read it carefully: some familiar commands may be defined somewhat differently in Atom BASIC. This chapter contains the following sections: * Miscellaneous Commands ** End, Stop ** High, Low, Toggle ** Input, Output, Reverse ** Pause ** Pauseclk ** Pauseus ** Nap ** Sleep Conventions Used in this Chapter END, STOP These commands stop program execution and place the Atom Pro in low power mode. All I/O pins will remain in their current state. END and STOP are identical in function. Syntax :END :STOP Notes To restart a stopped program, press the RESET button on the Atom Pro or power the Atom Pro OFF and back ON. HIGH, LOW, TOGGLE HIGH configures a pin as output and sets it high. LOW configures a pin as output and sets it low. TOGGLE configures a pin as output and switches its state from high to low or low to high. Syntax :high pin :low pin :toggle pin ::pin is a variable or constant that specifies the I/O pin to use. Examples high P4 ; makes P4 an output and sets it high (5V) low P10 ; makes P10 an output and sets it low (0V) high P4 ; makes P4 an output and sets it high. toggle P4 ; switches P4 from high to low. INPUT, OUTPUT, REVERSE INPUT sets a pin to be an input. OUTPUT sets a pin to be an output but does not set its state. REVERSE reverses the direction of a pin. Syntax :input pin :output pin :reverse pin ::pin is a variable or constant specifying the I/O pin affected. Notes These commands let you set the direction of a pin. Note that several commands (e.g. high, low, etc. automatically set the direction of certain pins so it may not be necessary to set them using input, output or reverse. This behavior is documented for the individual commands. Examples input P8 ; sets I/O pin 8 as an input. output P9 ; sets I/O pin 9 as an output serout P5\P6,NEO2400,5000,expd,ant,bat,hex4 cat\4 ; program continues here input P5 ; change P5 to an input In the last example, the serout command has set P5 to an output. Later, the input command is used to change it to an input. PAUSE Pause execution for a specified number of milliseconds. Syntax :pause milliseconds ::milliseconds is a variable or constant specifying the number of milliseconds (up to 32 bits, or 4,294,967,295 ms). Notes Pause is used to delay program execution. The duration of the pause can be from 1 ms to 4,294,967 seconds (which is approximately 1193 hours, or 49.7 days). While it is unlikely that longer pauses than this will be required, times shorter than 1 ms may be obtained with the pauseus and pauseclk commands. Examples See the traffic light program on page 23 for one example where pause could be used. Another example is shown under I2COUT on page 120. PAUSECLK Pause execution for a specified number of clock cycles. PAUSECLK is most useful for very short times, for longer times use PAUSE or PAUSEUS. Syntax :pauseclk cycles ::cycles is a variable or constant (up to 32 bits) specifying the number of clock cycles to pause. Notes Clock periods and timing are shown in the table below. Examples With an Atom Pro: pauseclk 2000 will cause program execution to pause for 2000 x 62.5 ns, or 125 µs. PAUSEUS Pause execution for a specified number of microseconds. Syntax :pauseus microseconds ::microseconds is a variable or constant specifying the number of microseconds to pause, up to 32 bits. Notes The pauseus command is used to pause program execution for short periods of time (from 1 µs to 4,294,967,295 µs, which is approximately 4,295 seconds, or 71.6 minutes, or 1.2 hours). The resolution of the pauseus command is 1000 times smaller than that of the pause command and 5 times greater than the pauseclk command. NAP The NAP command executes the processor's internal sleep mode for the specified time period. Power consumption is reduced in sleep mode. NAP is essentially a simplified version of SLEEP (see page 131). Syntax :nap period ::period is a variable or constant that determines the duration of the reduced power nap in units of 2 ms. Notes Times are approximate and may vary with temperature, supply voltage and manufacturing tolerances. The Atom Pro will immediately wake up from a nap if an interrupt occurs. The NAP command does not affect internal registers so your program will continue executing when the time expires. Example nap 2000 will put the Atom Pro in low power sleep state for 40 seconds. SLEEP The SLEEP command is similar to the NAP command except that it adds a number of options. To achieve minimum power consumption set all I/O pins to output and in the low state. (Don't set pins to "output" if they are connected to the outputs of other devices!) Syntax :sleep time{,mode} ::time is a variable or constant (up to 32 bits) that specifies the duration of the sleep in 2 ms increments (see the Important Note below). ::mode is an optional parameter with several possible values as described below. If mode is not specified, the sleep command is equivalent to the nap command. Modes Standby mode puts the processor to sleep and turns off the oscillator to save power. An external interrupt or reset must be used to wake up the processor. The time parameter is ignored. The following modes cause the clock multiplier to be set and puts the processor to sleep for the specified time. Important:' If the clock multiplier is set to 8, 16, 32 or 64 the 2 ms time increment is multiplied by the same factor. 14 Don't set pins to "output" if they are connected to the outputs of other devices! The following modes change the clock speed divisor without putting the processor to sleep. The time parameter is ignored. Same as DIRECTACTIVE except that all system registers, TimerV, SCI3 and the AD hardware are reset. The time parameter is ignored. '''''Notes Examples sleep 3000 will put the Atom Pro in low power sleep state for approximately 6 seconds. sleep 3000,sleepactive_8 will reduce the clock rate by a factor of 8, and put the Atom Pro in low power sleep state for approximately 48 seconds. sleep 1,sleepstandby will put the processor to sleep and turn off the oscillator. The processor will start when a reset or external interrupt is received. The time parameter (1, in this case) is ignored.